<?php
//initialize the session
if (!isset($_SESSION)) {
@session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
  $_SESSION['MM_id_target']=NULL;
	$_SESSION['MM_aut_target']=NULL;
	$_SESSION['MM_nmb_target']=NULL;
	$_SESSION['MM_tp_programa']=NULL;
	$_SESSION['MM_id_candidato']=NULL;
	$_SESSION['MM_id_empresa']=NULL;
	
  $logoutGoTo = "../private/login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php require_once('../Connections/miportal.php'); 
mysql_query("SET NAMES 'utf8'");
setlocale(LC_MONETARY, 'en_US');?>
<?php
$convocatoria=$_SESSION['MM_id_cat_convocatoria'];
mysql_select_db($database_miportal, $miportal);
$query_rs_ies = "SELECT *,(SELECT SUM(gt_monto) FROM `cor_donativo_empresa` WHERE `cor_donativo_empresa`.`id_cor_empresa_beneficiada`=`cor_empresa_beneficiada`.`id_cor_empresa_beneficiada`) AS monto_transferido FROM cor_empresa_beneficiada LEFT JOIN cat_empresa USING (id_cat_empresa) WHERE id_cat_convocatoria=$convocatoria AND tp_status_participacion=1 ORDER BY id_nom_fiscal ASC";
$rs_query = mysql_query($query_rs_ies, $miportal) or die(mysql_error());
$row_rs_ies = mysql_fetch_assoc($rs_query);
$totalRows_rs_empresas = mysql_num_rows($rs_query);
?>



<?php
if (!isset($_SESSION)) {
 @session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../private/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
<!--Hoja de estilo principal-->
<link href="../css/styletd2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="../css/menu.css"><!--Pemanggilan gambar favicon-->
<link rel="stylesheet" type="text/css" href="../css/mos-style.css">
 <!--pemanggilan file css-->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function popitup(url) {
	newwindow=window.open(url,'name','height=320,width=750,left=150,top=150');
	if (window.focus) {newwindow.focus()}
	return false;
}


</script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../addons/pager/jquery.tablesorter.pager.js"></script>
	<script src="../js/jquery.tablesorter.widgets.js"></script>
<script id="js">$(function(){

	// define pager options
	var pagerOptions = {
		// target the pager markup - see the HTML block below
		container: $(".pager"),
		// output string - default is '{page}/{totalPages}'; possible variables: {page}, {totalPages}, {startRow}, {endRow} and {totalRows}
		output: '{startRow} - {endRow} / {filteredRows} ({totalRows})',
		// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
		// table row set to a height to compensate; default is false
		fixedHeight: true,
		// remove rows from the table to speed up the sort of large tables.
		// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
		removeRows: false,
		// go to page selector - select dropdown that sets the current page
		cssGoto:	 '.gotoPage'
	};


	// Initialize tablesorter
	// ***********************
	$("table")
		.tablesorter({
			theme: 'blue',
			headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon!
			widthFixed: true,
			widgets: ['zebra', 'filter'],
			sortList: [[0,0]]
		})

		// initialize the pager plugin
		// ****************************
		.tablesorterPager(pagerOptions);

		// Delete a row
		// *************
		$('table').delegate('button.remove', 'click' ,function(){
			var t = $('table');
			// disabling the pager will restore all table rows
			t.trigger('disable.pager');
			// remove chosen row
			$(this).closest('tr').remove();
			// restore pager
			t.trigger('enable.pager');
		});

		

});</script>

</head>

<body>
 
 <header>
        <div id="background"></div><!--BackGround Menu header-->
		<div class="img_header_logo"></div>
		<span class="img_header_logo"><a href="http://fese.org.mx"><img src="../images/fese/FESE_home_logo.png"  height="90" alt="FESE" align="bottom" /></a></span>
		<div class="img_header_logo"></div>
		<?php include_once('../include/dir_coa_nav.php');?>
</header>

<center>
<div id="boxcontainer" style="width:1200px">
<div id="container">
  <p>&nbsp;</p>
  
  <div class="pager">
		Hoja: <select class="gotoPage"></select>
		<img src="../addons/pager/icons/first.png" class="first" alt="First" title="First page" />
		<img src="../addons/pager/icons/prev.png" class="prev" alt="Prev" title="Previous page" />
		<span class="pagedisplay"></span> <!-- this can be any element, including an input -->
		<img src="../addons/pager/icons/next.png" class="next" alt="Next" title="Next page" />
		<img src="../addons/pager/icons/last.png" class="last" alt="Last" title= "Last page" />
		<select class="pagesize">
			<option selected="selected" value="100">100</option>
			<option value="200">200</option>
			<option value="500">500</option>
		</select>
                        
	</div>
    <p>&nbsp;</p>
  
  <h2 align="left">Empresas participantes en esta convocatoria: <?php print $totalRows_rs_empresas?> </h2>
  
   <table class="tablesorter" style="width:95%">
   <thead class="data" style="text-align:center"> 
    <tr class="data">
    
      <th class="data" scope="col">NO.</th>
      <th class="data" scope="col">FOLIO</th>
      <th class="data"  scope="col">EMPRESA</th>
      <th class="data" scope="col">BENEFICIARIOS</th>
	  <th class="data" scope="col">DONATIVOS_REALIZADOS</th>
	  <th class="data" scope="col">DONATIVO_ESPERADO</th>
	  <th class="data" scope="col">SALDO_PENDIENTE</th>
      <th class="data" scope="col">REGISTRAR</th>
     </tr>
    </thead>
  <?php for ($i=1;$i<=$totalRows_rs_empresas; $i++){?>

    <tr>
      <td class="data" Style="width:25px;"><?php print $i; ?></td>
      <td class="data" Style="width:25px;"><?php echo $row_rs_ies['id_cat_empresa']; ?></td>
      <td class="data" Style="width:300px;"><?php echo (isset($row_rs_ies['gt_url_rfc'])&&!empty($row_rs_ies['gt_url_rfc'])?"<a target=\"_blank\" href=\"".$row_rs_ies['gt_url_rfc']."\">".$row_rs_ies['id_nom_fiscal']."</a>":$row_rs_ies['id_nom_fiscal']); ?></td>
      <td class="data" Style="width:100px;"><?php echo $row_rs_ies['gt_no_beneficiarios_ini']; ?></td>
	  <td class="data" Style="width:100px; text-align:right;">
      <a href="report_donativos.php" onclick="return popitup('report_donativos.php?var=<?php echo base64_encode($row_rs_ies['id_cor_empresa_beneficiada']+261)?>')"
	><?php echo (!empty($row_rs_ies['monto_transferido'])?money_format('%.2n',$row_rs_ies['monto_transferido']):"");?></a>

      </td>
	  <td class="data" Style="width:100px; text-align:right;"><?php echo (!empty($row_rs_ies['gt_monto_inicial']) ?money_format('%.2n',$row_rs_ies['gt_monto_inicial']):""); ?></td>
	  <td class="data" Style="width:100px; text-align:right;"><?php echo (!empty($row_rs_ies['gt_monto_inicial'])&&!empty($row_rs_ies['monto_transferido']) ?money_format('%.2n',($row_rs_ies['gt_monto_inicial']-$row_rs_ies['monto_transferido'])):money_format('%.2n',$row_rs_ies['gt_monto_inicial'])); ?></td>
      <td class="data" Style="width:25px;"><a href="../form/form_dir_coa_donativo.php<?php echo "?id_obj=".$row_rs_ies['id_cat_empresa'];?>" target="_self" >REGISTRAR</a></td>
	  
	  
    </tr>
	<?php 
	$row_rs_ies = mysql_fetch_assoc($rs_query);
  }?>
  </table>
  
  <p align="left">&nbsp;</p>
  <p align="left">&nbsp;</p>
    
  
</div>
<!--Container-->
<?php include_once('../include/dir_coa_rigth_container.php');?>
</div><!--Boxcontainer-->
</center>
  
 
</body>
</html>

